//
//  AIBalanceAlertView.m
//  Mia
//
//  Created by Vill on 2024/1/31.
//

#import "AIBalanceAlertView.h"

@interface AIBalanceAlertView ()

@property (nonatomic, strong) UIVisualEffectView *blurView; //模糊
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) UIButton *confirmBtn;   //确认
@property (nonatomic, strong) UILabel *alertTitle;    //标题
@property (nonatomic, strong) UILabel *detailLbl;     //详情
@property (nonatomic, strong) UIImageView *diamondImg; //钻石图片
@property (nonatomic, strong) UILabel *balanceLbl;     //钻石数量

@end

@implementation AIBalanceAlertView

- (instancetype)initWithCoins:(NSInteger)coins subtitle:(NSString *)subtitle{
    self = [super init];
    if (self) {
        self.contentView.backgroundColor = UIColor.clearColor;
        [self.contentView addSubview:self.blurView];
        [self.contentView addSubview:self.closeBtn];
        [self.contentView addSubview:self.confirmBtn];
        [self.contentView addSubview:self.alertTitle];
        
        [self.blurView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.top.mas_equalTo(self.contentView);
            make.height.mas_equalTo(PTW(350));
            make.bottom.mas_equalTo(self.contentView);
        }];
        [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(PTW(34));
            make.top.mas_equalTo(self.contentView).mas_offset(PTW(15));
            make.trailing.mas_equalTo(self.contentView).mas_offset(-PTW(15));
        }];
        [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.contentView).mas_offset(PTW(15));
            make.trailing.mas_equalTo(self.contentView).mas_offset(-PTW(15));
            make.bottom.mas_equalTo(self.contentView).mas_offset(-PTW(30));
            make.height.mas_equalTo(PTW(60));
        }];
        
        [self.alertTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView).mas_offset(PTW(20));
            make.centerX.mas_equalTo(self.contentView);
        }];
        
        [self.contentView addSubview:self.diamondImg];
        [self.contentView addSubview:self.balanceLbl];
        [self.diamondImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(PTW(70));
            make.centerX.mas_equalTo(self.contentView);
            make.top.mas_equalTo(self.alertTitle.mas_bottom).mas_offset(PTW(30));
        }];
        [self.balanceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView);
            make.top.mas_equalTo(self.diamondImg.mas_bottom).mas_offset(PTW(5));
        }];
        
        [self.contentView addSubview:self.detailLbl];
        [self.detailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView);
            make.bottom.mas_equalTo(self.confirmBtn.mas_top).mas_offset(-PTW(20));
        }];
        self.balanceLbl.text = [NSString stringWithFormat:@"%ld",coins];
        self.detailLbl.text = subtitle;
    }
    return self;
}

- (UIVisualEffectView *)blurView{
    if(!_blurView){
        UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        _blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
        _blurView.alpha = 0.9;
        _blurView.backgroundColor = [UIColor colorHex:@"#FFFFFF" alpha:0.3];
    }
    return _blurView;
}

-(UIButton *)closeBtn{
    if(!_closeBtn){
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:KImaged(@"ai_main_close") forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}

- (UIButton *)confirmBtn{
    if(!_confirmBtn){
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setTitle:@"Confirm" forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:[UIColor colorHex:@"#5C5C5C"] forState:UIControlStateNormal];
        _confirmBtn.titleLabel.font = [UIFont fontWithWeight:MTBold size:PTW(15)];
        _confirmBtn.backgroundColor = [UIColor whiteColor];
        _confirmBtn.layer.cornerRadius = PTW(30);
        _confirmBtn.layer.shadowColor = [UIColor colorHex:@"#FFFFFF" alpha:0.68].CGColor;
        _confirmBtn.layer.shadowOffset = CGSizeMake(0,0);
        _confirmBtn.layer.shadowOpacity = 1;
        _confirmBtn.layer.shadowRadius = 8;
        [_confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

- (UILabel *)alertTitle{
    if(!_alertTitle){
        _alertTitle = [UILabel new];
        _alertTitle.textColor = [UIColor whiteColor];
        _alertTitle.font = [UIFont fontWithWeight:MTBold size:PTW(22)];
        _alertTitle.textAlignment = NSTextAlignmentCenter;
        _alertTitle.numberOfLines = 0;
        _alertTitle.text = @"Your Balance";
    }
    return _alertTitle;
}

- (UILabel *)detailLbl{
    if(!_detailLbl){
        _detailLbl = [UILabel new];
        _detailLbl.textColor = [UIColor colorHex:@"#33FFC1"];
        _detailLbl.font = [UIFont fontWithWeight:MTBold size:PTW(12)];
        _detailLbl.textAlignment = NSTextAlignmentCenter;
        _detailLbl.numberOfLines = 0;
    }
    return _detailLbl;
}

- (UIImageView *)diamondImg{
    if(!_diamondImg){
        _diamondImg = [UIImageView new];
        _diamondImg.image = KImaged(@"ai_home_diamond");
    }
    return _diamondImg;
}

- (UILabel *)balanceLbl{
    if(!_balanceLbl){
        _balanceLbl = [UILabel new];
        _balanceLbl.textColor = [UIColor colorHex:@"#FFFFFF"];
        _balanceLbl.font = [UIFont fontWithWeight:MTBold size:PTW(22)];
        _balanceLbl.textAlignment = NSTextAlignmentCenter;
        _balanceLbl.numberOfLines = 0;
    }
    return _balanceLbl;
}

// 关闭
-(void)closeAction{
    [self dismiss];
}

// 确认
-(void)confirmAction{
    [self dismiss];
    if (self.certainBlock){
        self.certainBlock();
    }
}


@end
